package com.qyer.search.model.lastminute;

import static com.qyer.commons.utils.CommonUtils.cast2Double;
import static com.qyer.commons.utils.CommonUtils.cast2Int;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonFilter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.qyer.search.enums.TagStatus;
import com.qyer.search.enums.TagType;
import org.apache.commons.collections4.MapUtils;

import java.util.Map;

/**
 * Created by tangzheng on 16/7/18.
 */
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonFilter("ZTagFilter")
public class ZTag {
  private static final String FIELD_ID = "tid";
  private static final String FIELD_TAGNAME = "tag_name";
  private static final String FIELD_CHANNEL = "channel";

  @JsonIgnore
  private int tid;
  @JsonIgnore
  private String tag_name;
  @JsonIgnore
  private int channel;

  public ZTag(int tid, String tag_name, int channel) {
    this.tid = tid;
    this.tag_name = tag_name;
    this.channel = channel;
  }

  public static ZTag buildTag(Map<String, Object> dataMap) {
    if (MapUtils.isEmpty(dataMap)) {
      return null;
    }
    int id = cast2Int(dataMap.get(FIELD_ID));
    String tagName = String.valueOf(dataMap.get(FIELD_TAGNAME));
    int channel = cast2Int(dataMap.get(FIELD_CHANNEL));
    ZTag ztag = new ZTag(id, tagName, channel);
    return ztag;
  }

  public static String getFieldId() {
    return FIELD_ID;
  }

  public static String getFieldTagname() {
    return FIELD_TAGNAME;
  }

  public static String getFieldChannel() {
    return FIELD_CHANNEL;
  }

  public int getTid() {
    return tid;
  }

  public void setTid(int tid) {
    this.tid = tid;
  }

  public String getTag_name() {
    return tag_name;
  }

  public void setTag_name(String tag_name) {
    this.tag_name = tag_name;
  }

  public int getChannel() {
    return channel;
  }

  public void setChannel(int channel) {
    this.channel = channel;
  }

  @Override public boolean equals(Object o) {
    if (this == o)
      return true;
    if (o == null || getClass() != o.getClass())
      return false;

    ZTag zTag = (ZTag) o;

    if (tid != zTag.tid)
      return false;
    if (channel != zTag.channel)
      return false;
    return tag_name.equals(zTag.tag_name);

  }

  @Override public int hashCode() {
    int result = tid;
    result = 31 * result + tag_name.hashCode();
    result = 31 * result + channel;
    return result;
  }
}
